<template>
  <div class="template-list">
    <el-empty v-if="templates.length === 0" description="暂无数据" />
    <el-row v-else :gutter="15">
      <el-col style="margin-bottom: 10px;" v-for="template in templates" :key="template.id" :span="6">
        <el-card shadow="hover" class="template-card">
          <slot :row="template"></slot>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
/**
 * 模板卡片列表组件
 * @file index.vue
 */
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Clock, View } from '@element-plus/icons-vue'

const props = defineProps({
  /**
   * 模板数据数组
   * @type {Array}
   */
  templates: {
    type: Array,
    required: true
  }
})

const router = useRouter()

/**
 * 使用模板创建方案
 * @param {Object} template - 模板对象
 */
const useTemplate = (template) => {
  ElMessage.success(`已选择模板: ${template.name}`)
  router.push({
    path: '/tactical-plan/create',
    query: { templateId: template.id }
  })
}

/**
 * 查看模板详情
 * @param {Object} template - 模板对象
 */
const viewTemplate = (template) => {
  router.push(`/tactical-plan/detail/${template.id}`)
}

/**
 * 删除模板
 * @param {Object} template - 模板对象
 */
const deleteTemplate = (template) => {
  ElMessageBox.confirm(
    `确定要删除模板"${template.name}"吗？`,
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      ElMessage({
        type: 'success',
        message: '删除成功',
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '已取消删除',
      })
    })
}
</script>

<style lang="scss" scoped>
.template-list {
  margin-top: 20px;

  .template-card {
    height: 100%;
    transition: all 0.3s;
    border-radius: 8px;
    overflow: hidden;

    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 6px 16px rgba(64, 158, 255, 0.1);
    }

    ::v-deep {
      .el-card__body {
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 15px 10px;
      }
    }
  }
}
</style>